package com.cq.hd.admin.controller;

import com.cq.hd.admin.annotation.RequiresPermissionsDesc;
import com.cq.hd.common.enums.biz.FinancialAccountTypeEnum;
import com.cq.hd.common.response.Result;
import com.cq.hd.system.api.TbWithdrawalConfigApi;
import com.cq.hd.system.api.dto.WithdrawalConfigSaveDto;
import com.cq.hd.system.api.vo.WithdrawalConfigVo;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "提现配置相关接口")
@Slf4j
@RestController
@RequestMapping("/withdrawalConfig")
public class TbWithdrawalConfigController extends BaseController {

    private TbWithdrawalConfigApi withdrawalConfigApi;

    @Autowired
    public void setWithdrawalConfigApi(TbWithdrawalConfigApi withdrawalConfigApi) {
        this.withdrawalConfigApi = withdrawalConfigApi;
    }

    @ApiOperation(value = "提现配置详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "withdrawalUserType", value = "提现用户类型(1-商户本金，2-经纪人，3-商户补贴)", required = true, paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "financialAccountType", value = "资金账户类型，1-自建资金账户 2-平台资金账户", required = true, paramType = "query", dataType = "Long")
    })
    @ApiResponse(response = WithdrawalConfigVo.class, code = 200, message = "接口返回对象参数")
    @RequiresPermissions("systemConfig:withdrawalConfig:detail")
    @RequiresPermissionsDesc(menu = {"系统管理", "提现配置"}, button = "详情")
    @GetMapping("/details")
    public Result<WithdrawalConfigVo> details(Integer withdrawalUserType, Integer financialAccountType) {
        if (financialAccountType == null) {
            financialAccountType = FinancialAccountTypeEnum.SELF.getValue();
        }
        return withdrawalConfigApi.details(withdrawalUserType, financialAccountType);
    }

    @ApiOperation(value = "保存提现配置")
    @ApiImplicitParam(name = "withdrawalConfigSaveDto", value = "提现用户类型(1-商户本金，2-经纪人，3-商户补贴)", paramType = "body", dataType = "WithdrawalConfigSaveDto")
    @RequiresPermissions("systemConfig:withdrawalConfig:save")
    @RequiresPermissionsDesc(menu = {"系统管理", "提现配置"}, button = "保存")
    @PostMapping("/save")
    public Result<Object> saveWithdrawalConfig(@Validated @RequestBody WithdrawalConfigSaveDto withdrawalConfigSaveDto) {
        if (withdrawalConfigSaveDto.getFinancialAccountType() == null) {
            withdrawalConfigSaveDto.setFinancialAccountType(FinancialAccountTypeEnum.SELF.getValue());
        }
        return withdrawalConfigApi.saveWithdrawalConfig(withdrawalConfigSaveDto);
    }
}
